<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>JVM虚拟机 | 自由·生活</title>
    <meta name="generator" content="VuePress 1.5.4">
    <link rel="icon" href="images/favicon.ico">
    <script language="javascript" type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/MouseClickEffect.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
    <meta name="description" content="脱离生存而生活，寻求自由">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <link rel="preload" href="/assets/css/0.styles.8c3033ea.css" as="style"><link rel="preload" href="/assets/js/app.0e76bb72.js" as="script"><link rel="preload" href="/assets/js/3.c5829877.js" as="script"><link rel="preload" href="/assets/js/1.695f3f80.js" as="script"><link rel="preload" href="/assets/js/229.0f8a6911.js" as="script"><link rel="prefetch" href="/assets/js/10.fdc11bc7.js"><link rel="prefetch" href="/assets/js/100.3e29fa54.js"><link rel="prefetch" href="/assets/js/101.19f861f4.js"><link rel="prefetch" href="/assets/js/102.0eb344c2.js"><link rel="prefetch" href="/assets/js/103.167b5aab.js"><link rel="prefetch" href="/assets/js/104.3463b648.js"><link rel="prefetch" href="/assets/js/105.fc782f3d.js"><link rel="prefetch" href="/assets/js/106.b2d60f6a.js"><link rel="prefetch" href="/assets/js/107.91f5548b.js"><link rel="prefetch" href="/assets/js/108.8bcbfcd7.js"><link rel="prefetch" href="/assets/js/109.a0dd87a3.js"><link rel="prefetch" href="/assets/js/11.5d72653a.js"><link rel="prefetch" href="/assets/js/110.8d3b5064.js"><link rel="prefetch" href="/assets/js/111.6e109181.js"><link rel="prefetch" href="/assets/js/112.7130a6e7.js"><link rel="prefetch" href="/assets/js/113.6c962a0e.js"><link rel="prefetch" href="/assets/js/114.82175aae.js"><link rel="prefetch" href="/assets/js/115.a83e6a2d.js"><link rel="prefetch" href="/assets/js/116.70ebc8b4.js"><link rel="prefetch" href="/assets/js/117.368509d0.js"><link rel="prefetch" href="/assets/js/118.54fdc470.js"><link rel="prefetch" href="/assets/js/119.64d2a2a3.js"><link rel="prefetch" href="/assets/js/12.bfde6b78.js"><link rel="prefetch" href="/assets/js/120.5b47488f.js"><link rel="prefetch" href="/assets/js/121.82865d4b.js"><link rel="prefetch" href="/assets/js/122.619e60ca.js"><link rel="prefetch" href="/assets/js/123.66c3fb26.js"><link rel="prefetch" href="/assets/js/124.4381768b.js"><link rel="prefetch" href="/assets/js/125.2f39619b.js"><link rel="prefetch" href="/assets/js/126.0c622bc6.js"><link rel="prefetch" href="/assets/js/127.caee15ee.js"><link rel="prefetch" href="/assets/js/128.99714900.js"><link rel="prefetch" href="/assets/js/129.ff59083b.js"><link rel="prefetch" href="/assets/js/13.2b3528b1.js"><link rel="prefetch" href="/assets/js/130.76df0e89.js"><link rel="prefetch" href="/assets/js/131.2333a328.js"><link rel="prefetch" href="/assets/js/132.65cff4f4.js"><link rel="prefetch" href="/assets/js/133.2c0991bc.js"><link rel="prefetch" href="/assets/js/134.fe5fc3a5.js"><link rel="prefetch" href="/assets/js/135.aef0a809.js"><link rel="prefetch" href="/assets/js/136.90fd1b1d.js"><link rel="prefetch" href="/assets/js/137.07750a3f.js"><link rel="prefetch" href="/assets/js/138.723bd2c0.js"><link rel="prefetch" href="/assets/js/139.d22450b7.js"><link rel="prefetch" href="/assets/js/14.b769124c.js"><link rel="prefetch" href="/assets/js/140.1659de26.js"><link rel="prefetch" href="/assets/js/141.f713c5ec.js"><link rel="prefetch" href="/assets/js/142.63ebd83f.js"><link rel="prefetch" href="/assets/js/143.404a833f.js"><link rel="prefetch" href="/assets/js/144.3e0107ef.js"><link rel="prefetch" href="/assets/js/145.cef80531.js"><link rel="prefetch" href="/assets/js/146.c68d17d7.js"><link rel="prefetch" href="/assets/js/147.0af3acbb.js"><link rel="prefetch" href="/assets/js/148.9f0d2452.js"><link rel="prefetch" href="/assets/js/149.28785960.js"><link rel="prefetch" href="/assets/js/15.7c3421d9.js"><link rel="prefetch" href="/assets/js/150.bf310c33.js"><link rel="prefetch" href="/assets/js/151.de6313cc.js"><link rel="prefetch" href="/assets/js/152.91a567b5.js"><link rel="prefetch" href="/assets/js/153.cfe26382.js"><link rel="prefetch" href="/assets/js/154.047349d0.js"><link rel="prefetch" href="/assets/js/155.6923503c.js"><link rel="prefetch" href="/assets/js/156.2443e22f.js"><link rel="prefetch" href="/assets/js/157.fac2fc32.js"><link rel="prefetch" href="/assets/js/158.3d470963.js"><link rel="prefetch" href="/assets/js/159.9512719e.js"><link rel="prefetch" href="/assets/js/16.baa49355.js"><link rel="prefetch" href="/assets/js/160.1a610cc3.js"><link rel="prefetch" href="/assets/js/161.b240977c.js"><link rel="prefetch" href="/assets/js/162.cfb78d5a.js"><link rel="prefetch" href="/assets/js/163.3c935aea.js"><link rel="prefetch" href="/assets/js/164.0188664b.js"><link rel="prefetch" href="/assets/js/165.6f4ba8e0.js"><link rel="prefetch" href="/assets/js/166.32b92de7.js"><link rel="prefetch" href="/assets/js/167.1087cc58.js"><link rel="prefetch" href="/assets/js/168.7e81ac69.js"><link rel="prefetch" href="/assets/js/169.5270c30b.js"><link rel="prefetch" href="/assets/js/17.2270e174.js"><link rel="prefetch" href="/assets/js/170.1d6bc941.js"><link rel="prefetch" href="/assets/js/171.e3781bc6.js"><link rel="prefetch" href="/assets/js/172.54d7bc4b.js"><link rel="prefetch" href="/assets/js/173.a88f9e1f.js"><link rel="prefetch" href="/assets/js/174.7d882351.js"><link rel="prefetch" href="/assets/js/175.7a0c6feb.js"><link rel="prefetch" href="/assets/js/176.12b22e86.js"><link rel="prefetch" href="/assets/js/177.b2230eac.js"><link rel="prefetch" href="/assets/js/178.023ba5be.js"><link rel="prefetch" href="/assets/js/179.53fa03a8.js"><link rel="prefetch" href="/assets/js/18.988151ff.js"><link rel="prefetch" href="/assets/js/180.f17c3614.js"><link rel="prefetch" href="/assets/js/181.8872481a.js"><link rel="prefetch" href="/assets/js/182.c57e38bc.js"><link rel="prefetch" href="/assets/js/183.7085d12e.js"><link rel="prefetch" href="/assets/js/184.aa164e5b.js"><link rel="prefetch" href="/assets/js/185.b7ed0f6b.js"><link rel="prefetch" href="/assets/js/186.f08304c9.js"><link rel="prefetch" href="/assets/js/187.4a10e63d.js"><link rel="prefetch" href="/assets/js/188.f0463437.js"><link rel="prefetch" href="/assets/js/189.cff969e0.js"><link rel="prefetch" href="/assets/js/19.c196a261.js"><link rel="prefetch" href="/assets/js/190.adc3524b.js"><link rel="prefetch" href="/assets/js/191.a14895a8.js"><link rel="prefetch" href="/assets/js/192.e595f819.js"><link rel="prefetch" href="/assets/js/193.3cbcef2c.js"><link rel="prefetch" href="/assets/js/194.55530a96.js"><link rel="prefetch" href="/assets/js/195.1a834f79.js"><link rel="prefetch" href="/assets/js/196.001dd10b.js"><link rel="prefetch" href="/assets/js/197.4b9de142.js"><link rel="prefetch" href="/assets/js/198.955a06ea.js"><link rel="prefetch" href="/assets/js/199.9d63eea7.js"><link rel="prefetch" href="/assets/js/20.74b35545.js"><link rel="prefetch" href="/assets/js/200.8fe0777d.js"><link rel="prefetch" href="/assets/js/201.a91425c3.js"><link rel="prefetch" href="/assets/js/202.5b89464a.js"><link rel="prefetch" href="/assets/js/203.e48d18e2.js"><link rel="prefetch" href="/assets/js/204.6cbc5c79.js"><link rel="prefetch" href="/assets/js/205.d26879e9.js"><link rel="prefetch" href="/assets/js/206.fd8688f3.js"><link rel="prefetch" href="/assets/js/207.ef25eb3d.js"><link rel="prefetch" href="/assets/js/208.9f0e5ab2.js"><link rel="prefetch" href="/assets/js/209.cbd7c763.js"><link rel="prefetch" href="/assets/js/21.3cbc9110.js"><link rel="prefetch" href="/assets/js/210.6b733c20.js"><link rel="prefetch" href="/assets/js/211.2b986a0a.js"><link rel="prefetch" href="/assets/js/212.faee0dc6.js"><link rel="prefetch" href="/assets/js/213.7ed75653.js"><link rel="prefetch" href="/assets/js/214.825d2d93.js"><link rel="prefetch" href="/assets/js/215.251aa760.js"><link rel="prefetch" href="/assets/js/216.11962b03.js"><link rel="prefetch" href="/assets/js/217.62e3335a.js"><link rel="prefetch" href="/assets/js/218.a7c3b793.js"><link rel="prefetch" href="/assets/js/219.5ff63a4c.js"><link rel="prefetch" href="/assets/js/22.d2507cce.js"><link rel="prefetch" href="/assets/js/220.28ea20d6.js"><link rel="prefetch" href="/assets/js/221.6108e4e1.js"><link rel="prefetch" href="/assets/js/222.73443d85.js"><link rel="prefetch" href="/assets/js/223.e115734d.js"><link rel="prefetch" href="/assets/js/224.499e0bab.js"><link rel="prefetch" href="/assets/js/225.70887ebb.js"><link rel="prefetch" href="/assets/js/226.e683c623.js"><link rel="prefetch" href="/assets/js/227.06f8bc32.js"><link rel="prefetch" href="/assets/js/228.82faf31a.js"><link rel="prefetch" href="/assets/js/23.8da30b89.js"><link rel="prefetch" href="/assets/js/230.f895ca67.js"><link rel="prefetch" href="/assets/js/231.34717d1d.js"><link rel="prefetch" href="/assets/js/232.c7857239.js"><link rel="prefetch" href="/assets/js/233.6b7bcffd.js"><link rel="prefetch" href="/assets/js/234.0e0da6a5.js"><link rel="prefetch" href="/assets/js/235.5bc065c0.js"><link rel="prefetch" href="/assets/js/236.3e91ceb0.js"><link rel="prefetch" href="/assets/js/237.9116740e.js"><link rel="prefetch" href="/assets/js/238.8c792409.js"><link rel="prefetch" href="/assets/js/239.b4d8dfb8.js"><link rel="prefetch" href="/assets/js/24.3014a3d4.js"><link rel="prefetch" href="/assets/js/240.a1e61d58.js"><link rel="prefetch" href="/assets/js/241.3c016709.js"><link rel="prefetch" href="/assets/js/242.f8620e3f.js"><link rel="prefetch" href="/assets/js/243.8f53f134.js"><link rel="prefetch" href="/assets/js/244.424903c4.js"><link rel="prefetch" href="/assets/js/245.96c86aae.js"><link rel="prefetch" href="/assets/js/25.03ca3aa9.js"><link rel="prefetch" href="/assets/js/26.4916e6b8.js"><link rel="prefetch" href="/assets/js/27.f9aab712.js"><link rel="prefetch" href="/assets/js/28.1dfbff97.js"><link rel="prefetch" href="/assets/js/29.f7a69544.js"><link rel="prefetch" href="/assets/js/30.e3062801.js"><link rel="prefetch" href="/assets/js/31.a510760d.js"><link rel="prefetch" href="/assets/js/32.7d281288.js"><link rel="prefetch" href="/assets/js/33.6ee8ebed.js"><link rel="prefetch" href="/assets/js/34.b32e8d79.js"><link rel="prefetch" href="/assets/js/35.59d10d28.js"><link rel="prefetch" href="/assets/js/36.e1bcc1a4.js"><link rel="prefetch" href="/assets/js/37.f6c202dd.js"><link rel="prefetch" href="/assets/js/38.f8d5161a.js"><link rel="prefetch" href="/assets/js/39.1b4b64a0.js"><link rel="prefetch" href="/assets/js/4.77ea1544.js"><link rel="prefetch" href="/assets/js/40.efb0ab3f.js"><link rel="prefetch" href="/assets/js/41.85c7d269.js"><link rel="prefetch" href="/assets/js/42.36b0df70.js"><link rel="prefetch" href="/assets/js/43.c3cc85ee.js"><link rel="prefetch" href="/assets/js/44.b1575b98.js"><link rel="prefetch" href="/assets/js/45.8de97fe3.js"><link rel="prefetch" href="/assets/js/46.1fe43d4f.js"><link rel="prefetch" href="/assets/js/47.70a2e6cc.js"><link rel="prefetch" href="/assets/js/48.bb81e90c.js"><link rel="prefetch" href="/assets/js/49.8f4841fa.js"><link rel="prefetch" href="/assets/js/5.b3344219.js"><link rel="prefetch" href="/assets/js/50.e7216bda.js"><link rel="prefetch" href="/assets/js/51.1a2faa73.js"><link rel="prefetch" href="/assets/js/52.f625df74.js"><link rel="prefetch" href="/assets/js/53.b0067c47.js"><link rel="prefetch" href="/assets/js/54.0c85623e.js"><link rel="prefetch" href="/assets/js/55.491eeca5.js"><link rel="prefetch" href="/assets/js/56.8c9ffe2c.js"><link rel="prefetch" href="/assets/js/57.51902d8c.js"><link rel="prefetch" href="/assets/js/58.6d40a504.js"><link rel="prefetch" href="/assets/js/59.dbb8914b.js"><link rel="prefetch" href="/assets/js/6.a7455cf0.js"><link rel="prefetch" href="/assets/js/60.99f5caf1.js"><link rel="prefetch" href="/assets/js/61.ad9ebd9b.js"><link rel="prefetch" href="/assets/js/62.8c2c2783.js"><link rel="prefetch" href="/assets/js/63.2334b133.js"><link rel="prefetch" href="/assets/js/64.c79651bc.js"><link rel="prefetch" href="/assets/js/65.791edb2c.js"><link rel="prefetch" href="/assets/js/66.bd09db30.js"><link rel="prefetch" href="/assets/js/67.1311433b.js"><link rel="prefetch" href="/assets/js/68.8be881a0.js"><link rel="prefetch" href="/assets/js/69.f9bb1936.js"><link rel="prefetch" href="/assets/js/7.274fc010.js"><link rel="prefetch" href="/assets/js/70.77e0e02e.js"><link rel="prefetch" href="/assets/js/71.da2cc493.js"><link rel="prefetch" href="/assets/js/72.f4a80206.js"><link rel="prefetch" href="/assets/js/73.8d4c37c8.js"><link rel="prefetch" href="/assets/js/74.7a7304d5.js"><link rel="prefetch" href="/assets/js/75.2e6d01bf.js"><link rel="prefetch" href="/assets/js/76.7de509a7.js"><link rel="prefetch" href="/assets/js/77.e5e58459.js"><link rel="prefetch" href="/assets/js/78.1590a03f.js"><link rel="prefetch" href="/assets/js/79.a96442ae.js"><link rel="prefetch" href="/assets/js/8.26184cc0.js"><link rel="prefetch" href="/assets/js/80.76d4faa5.js"><link rel="prefetch" href="/assets/js/81.c79d5483.js"><link rel="prefetch" href="/assets/js/82.47926428.js"><link rel="prefetch" href="/assets/js/83.ec12a53e.js"><link rel="prefetch" href="/assets/js/84.72120681.js"><link rel="prefetch" href="/assets/js/85.30643e8b.js"><link rel="prefetch" href="/assets/js/86.64375c3f.js"><link rel="prefetch" href="/assets/js/87.7a86109f.js"><link rel="prefetch" href="/assets/js/88.68858482.js"><link rel="prefetch" href="/assets/js/89.00d57e24.js"><link rel="prefetch" href="/assets/js/9.56db4e9b.js"><link rel="prefetch" href="/assets/js/90.b7f9de16.js"><link rel="prefetch" href="/assets/js/91.e9a8e6fb.js"><link rel="prefetch" href="/assets/js/92.0b986faf.js"><link rel="prefetch" href="/assets/js/93.7c26025a.js"><link rel="prefetch" href="/assets/js/94.c39f793d.js"><link rel="prefetch" href="/assets/js/95.b74865a0.js"><link rel="prefetch" href="/assets/js/96.62558dca.js"><link rel="prefetch" href="/assets/js/97.945f9035.js"><link rel="prefetch" href="/assets/js/98.be789959.js"><link rel="prefetch" href="/assets/js/99.1adf100e.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8c3033ea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-cd01cc30><div data-v-cd01cc30><div id="loader-wrapper" class="loading-wrapper" data-v-4cd7a24a data-v-cd01cc30 data-v-cd01cc30><div class="loader-main" data-v-4cd7a24a><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-623c7d26 data-v-cd01cc30 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>自由·生活</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div class="hide" data-v-cd01cc30><header class="navbar" data-v-cd01cc30><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/avatar.jpg" alt="自由·生活" class="logo"> <span class="site-name">自由·生活</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-cd01cc30></div> <aside class="sidebar" data-v-cd01cc30><div class="personal-info-wrapper" data-v-2a0ed2ae data-v-cd01cc30><img src="/images/avatar.jpg" alt="author-avatar" class="personal-img" data-v-2a0ed2ae> <h3 class="name" data-v-2a0ed2ae>
    丶忆yu'man
  </h3> <div class="num" data-v-2a0ed2ae><div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>217</h3> <h6 data-v-2a0ed2ae>文章</h6></div> <div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>15</h3> <h6 data-v-2a0ed2ae>标签</h6></div></div> <hr data-v-2a0ed2ae></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/" aria-current="page" class="sidebar-link">码农生涯</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>码农生涯</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blogs/码农生涯/interview/java-interview-questions.html" class="sidebar-link">Java面试题</a></li><li><a href="/blogs/码农生涯/interview/算法.html" class="sidebar-link">算法</a></li><li><a href="/blogs/码农生涯/interview/Java基础.html" class="sidebar-link">Java基础</a></li><li><a href="/blogs/码农生涯/interview/计算机网络.html" class="sidebar-link">计算机网络</a></li><li><a href="/blogs/码农生涯/interview/数据库.html" class="sidebar-link">数据库</a></li><li><a href="/blogs/码农生涯/interview/JVM虚拟机.html" class="active sidebar-link">JVM虚拟机</a></li><li><a href="/blogs/码农生涯/interview/多线程.html" class="sidebar-link">多线程</a></li><li><a href="/blogs/码农生涯/interview/操作系统.html" class="sidebar-link">操作系统</a></li><li><a href="/blogs/码农生涯/interview/redis.html" class="sidebar-link">redis</a></li><li><a href="/blogs/码农生涯/interview/Spring.html" class="sidebar-link">Spring</a></li><li><a href="/blogs/码农生涯/interview/Linux.html" class="sidebar-link">Linux</a></li><li><a href="/blogs/码农生涯/interview/设计模式.html" class="sidebar-link">设计模式</a></li><li><a href="/blogs/码农生涯/interview/开放问题.html" class="sidebar-link">开放问题</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-623c7d26 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>JVM虚拟机</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div data-v-cd01cc30><main class="page"><div class="page-title" style="display:none;"><h1 class="title">JVM虚拟机</h1> <div data-v-8bc6ae5c><i class="iconfont reco-account" data-v-8bc6ae5c><span data-v-8bc6ae5c>丶忆yu'man</span></i> <i class="iconfont reco-date" data-v-8bc6ae5c><span data-v-8bc6ae5c>2021-03-31</span></i> <i class="iconfont reco-eye" data-v-8bc6ae5c><span id="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/interview/JVM%E8%99%9A%E6%8B%9F%E6%9C%BA.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-8bc6ae5c><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-8bc6ae5c><span class="tag-item" data-v-8bc6ae5c>面试</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><div class="custom-block tip"><p>Java好难，面试让我明白了</p></div> <h1 id="jvm虚拟机">JVM虚拟机</h1> <h2 id="内存管理">内存管理</h2> <h3 id="内存分布">内存分布</h3> <p>JVM中的内存分布主要分为线程公有的和线程私有的，线程公有的内存区域包括Java堆和方法区，线程私有的内存区域包括程序计数器、虚拟机栈、本地方法区。</p> <ul><li><p>Java堆</p> <ul><li><p>Java堆介绍：堆主要是用来存储数组对象和实例对象的地方，也是JVM中经常发生GC操作的区域，Java堆中主要是按照分代收集算法来进行GC操作的，因此堆中又分为新生代和老年代，其中新生代又可分为Eden区、两个survivor区。</p></li> <li><p>对象内存分配</p> <p>在Java堆中为对象分配内存主要有两种方式，指针碰撞和空闲列表，选择哪种方式主要取决是Java堆中的内存是否规整，也就是说取决于GC使用的哪种算法。</p> <p>指针碰撞：在内存中管理一个指针，这个指针将内存空间分为两边，一边是已经使用的内存，一边是空闲内存，因此当为对象分配内存时，只需要将指针往空闲内存的方向进行移动，这也需要内存是规整时才能够实现。</p> <p>空闲列表：使用一个列表来对空闲内存块进行管理，为对象分配内存时，只需要从列表中取出符合大小的内存块。</p></li> <li><p>对象访问</p> <p>对象访问也主要分为两种方式：直接指针和使用句柄访问。JVM中采用的是直接指针的方式。</p> <p>直接指针：虚拟机栈中的引用直接指向Java堆中的对象地址。</p> <p>使用句柄访问：在Java堆中开辟出一块句柄池内存，然后将对象的地址引用放入句柄池中，虚拟机栈中的引用直接句柄池中的地址，然后通过句柄去访问对象的实际地址。</p> <p>比较：直接指针的方式访问更加方便，无需访问两次，并且使用更少空间，但是当对象被垃圾回收或者进行修改后，需要修改虚拟机栈中的引用地址，而使用句柄的方式可以通过修改句柄池中的实际对象地址来实现。</p></li></ul></li> <li><p>方法区</p> <p>方法区个人理解主要存储一个静态的，不变的数据，例如被虚拟机加载的类信息、静态变量、常量以及运行时常量池等，其中运行时常量池主要存储编译器生成的各种字面量和符号引用，字面量主要包括字符串池、八种基本数据类型、常量等，而符号引用主要包括一些类信息：全限定名、字段的名称和描述符、方法的名称和描述符。</p></li> <li><p>虚拟机栈</p> <p>当一个方法执行时会创建一个栈帧，栈帧主要用来存储局部变量表、操作数栈、动态链接、方法出口等信息，一个方法的执行就是一个栈帧从虚拟机栈中入栈到出栈的过程。</p></li> <li><p>程序计数器</p> <p>程序计数器是每个线程私有的，程序计数器的作用主要是用来记录当前线程所执行到的字节码的行号</p></li> <li><p>本地方法区</p> <p>本地方法区能够调用本地方法，这也为其它语言的方法提供了接口，能够在Java中进行调用。</p></li></ul> <h3 id="oom溢出情况">OOM溢出情况</h3> <ol><li>Java堆
<ul><li>没有足够的空间为对象分配内存，也就是出现大规模的内存泄漏，造成OOM。</li></ul></li> <li>方法区
<ul><li>类溢出：当定义的类过多时，方法区中没有内存存储类信息</li> <li>运行时常量池溢出：不断往字符串池中加入新的字符串，造成字符串池溢出</li></ul></li> <li>虚拟机栈
<ul><li>栈溢出：线程请求的栈深度大于虚拟机栈允许的最大深度，报StackOverflowError</li> <li>内存溢出：当线程允许动态拓展时，但是无法从JVM中分配足够的内存，报OOM</li></ul></li> <li>本地方法区</li></ol> <h3 id="jmm内存模型">JMM内存模型</h3> <p>JVM中有一块主内存，Java中的所有变量都存储在主内存中，这对每个线程都是共享的，而每个线程又有自己的工作内存，工作内存中存储的只是主内存中变量的拷贝，当线程对变量进行修改时也是发生在自己的工作内存中的，每个线程的工作内存对于其它线程是不共享的，因此线程之间的通信是通过主内存来进行交互的，修改一个变量后写入主内存，然后其它线程再从主内存中读取。</p> <h2 id="垃圾回收">垃圾回收</h2> <h3 id="简述垃圾回收">简述垃圾回收</h3> <ol><li>对象死亡</li> <li>垃圾回收算法</li> <li>垃圾收集器</li></ol> <h3 id="判断对象死亡">判断对象死亡</h3> <p>判断对象死亡的算法主要有两种：</p> <ol><li><p>引用计数法</p> <p>每个对象中都有一个引用计数器，这个计数器就是记录这个对象被引用的次数，在任意时刻这个对象引用计数器的值为0的话，代表这个对象是已经死亡的，然后就可以回收，但是对象之间可能会产生循环引用问题，例如A引用B，B引用A，那么这两个对象永远都不会被回收，造成内存泄漏。</p></li> <li><p>可达性分析法</p> <p>通过一个树结构来记录对象的引用，从根节点GCRoots结点出发，从上往下进行搜索，节点走过的路径被称为引用链，规定任意一个对象结点到GCRoots结点之间没有引用链相连的话，那么代表不可达，也就是这个对象是已经死亡的对象。</p> <p>GCRoots对象结点：个人理解一般都是不变对象，例如虚拟机栈中的引用对象、静态对象、常量对象、本地方法区中的引用对象。</p></li></ol> <h3 id="引用类型">引用类型</h3> <ul><li><p>强引用</p> <p>在任意时刻JVM都不会回收的引用对象，当Java虚拟机中的内存不足时，会出现OOM异常。</p></li> <li><p>软引用</p> <p>在一般情况下不会进行回收的引用对象，但是当Java虚拟机中的内存不足时，发生GC操作就会回收软引用指向的对象。</p></li> <li><p>弱引用</p> <p>弱引用指向的对象生命周期比较短暂，在下一次GC时就会被回收，典型代表对象ThreadLocal。</p></li> <li><p>虚引用</p> <p>虚引用对象可以认为是不存在的，在任意时刻GC都可能回收它。</p></li></ul> <h3 id="threadlocal弱引用">ThreadLocal弱引用</h3> <ol><li><p>简述ThreadLocal</p> <p>ThreadLocal对象是以一个Map的形式存在，其中Map的Entry元素可以认为是线程的私有变量，这也是保证线程之间的数据访问隔离的方式。其中Map的key就是一个弱引用，而value就是一个线程变量。</p></li> <li><p>为什么ThreadLocal是弱引用，为什么不使用强引用</p> <p>ThreadLocal使用弱引用的原因主要是当一个线程销毁后能够及时回收线程的对象，例如当我们使用线程池的方式来管理线程时，当采用强引用时这个线程的对象一直会存活到线程的结束，造成内存泄漏问题。</p></li> <li><p>ThreadLocal弱引用的问题</p> <p>使用弱引用时也会造成内存泄漏问题，在GC后，ThreadLocalMap中对象的key会被回收，但是value值还是存在，因此还是会出现内存泄漏问题，所以在不用ThreadLocal中的对象后，应该手动调用remove()方法来清除value值。</p> <p>但是在虚拟机中对线程的ThreadLocalMap对象进行get和put操作时，会检查Map中key为空的对象，如果key为null，就会进行回收，但是如果线程长时期不对ThreadLocal进行操作的话，就会出现内存泄漏。</p></li></ol> <h3 id="gc算法">GC算法</h3> <ul><li><p>标记-清除</p> <p>标记-清除算法是对Java堆中所有需要回收的对象进行标记，标记完成后统一进行回收，这种算法首先GC效率不高，另外也会造成空间碎片问题，当碎片太小时，就无法为内存更大的对象分配内存。</p></li> <li><p>复制</p> <p>复制算法主要是针对于新生代进行回收，这个算法将内存区域分为Eden区、两个Survivor区，每次都使用Eden区和一块Survivor区域来给对象分配内存，当发生GC操作时，会将这两块区域中还存活的对象放入到另外一块Survivor区域，然后一次性清除这两块区域内存，Eden区和两块Survivor区域的占比是8:1:1。</p> <p>对象在新生代中回收的过程，进入老年代的过程：</p> <p>一个对象最开始在新生代中分配内存，大对象会直接进入老年代，虚拟机默认的大对象参数是2M，然后对象在GC操作时，如果已死亡，就进行回收，如果还存活，就会被移入另外一块Survivor区域，另外每个对象都会有一个年龄计数器，经历一次GC年龄就加1，当年龄达到了虚拟机规定的最大年龄时，就会进入老年代。</p></li> <li><p>标记整理</p> <p>标记整理算法应该是相对标记清除算法的改进，标记出所有需要回收的对象，然后将仍然存活的对象按照内存区域向前进行移动，最后所有存活对象就会连续在一起，然后清除掉一次性清除端两边的内存。</p></li></ul> <h3 id="gc收集器">GC收集器</h3> <ul><li><p>Parallel Scanvenge</p></li> <li><p>Parallel Old</p></li> <li><p>CMS</p></li> <li><p>G1</p></li></ul> <h3 id="gc类型">GC类型</h3> <ul><li>minor gc：对新生代进行gc，也是经常发生的gc操作，回收速度较快</li> <li>major gc：对老年代进行gc，回收速度较慢，应该尽量减少老年代的gc操作。</li> <li>full gc：对新生代和老年代都进行gc操作</li></ul> <h3 id="默认参数">默认参数</h3> <div class="language-java line-numbers-mode"><pre class="language-java"><code>新生代<span class="token operator">:</span>老年代 <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">;</span>
<span class="token class-name">Eden</span><span class="token operator">:</span><span class="token class-name">Survivor</span><span class="token operator">:</span><span class="token class-name">Survivor</span><span class="token operator">=</span><span class="token number">8</span><span class="token operator">:</span><span class="token number">1</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">;</span>
大对象默认参数 <span class="token operator">-</span>XX<span class="token operator">:</span><span class="token class-name">PretenureSizeThreshold</span><span class="token operator">=</span><span class="token number">2</span>M<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="类加载">类加载</h2> <h3 id="类加载过程">类加载过程</h3> <p>类加载就是将类信息从class文件中加载到虚拟机中，并对其中的数据进行相应操作。</p> <ul><li><p>加载</p> <p>通过类的全限定名，在方法区中产生对应类型的数据结构，然后实例化一个Java.lang.class实例，作为这个类在方法区中的访问入口。</p></li> <li><p>验证</p> <p>这个过程主要就是验证class文中的类信息是否符合虚拟机的规范，不能危害到虚拟机自身的安全。</p></li> <li><p>准备</p> <p>准备阶段是为类的静态变量在方法区中分配内存，并赋予初始值。</p></li> <li><p>解析</p> <p>将类在常量池中的符号引用转换为直接引用，这个主要是针对类的一些静态属性和静态方法，能够直接通过类名的方式进行调用。</p></li> <li><p>初始化</p> <p>初始化阶段就是真正运行Java代码的过程，为静态变量赋值并执行静态代码块中的内容，当前类的初始化必须在父类的初始化之后进行。</p></li></ul> <h3 id="类加载器">类加载器</h3> <ul><li><p>启动类加载器Bootstrap ClassLoader</p> <p>启动类加载器是最上层的加载器，主要负责加载Java中的核心类，会加载存放在lib目录下的类库。</p></li> <li><p>拓展类加载器Extension ClassLoader</p> <p>拓展类加载器主要负责加载lib\ext目录下的类库。</p></li> <li><p>应用程序类加载器System ClassLoader</p> <p>应用程序类加载器也被称为系统类加载器，主要负责加CLASSPATH目录的类，也可以认为是用户自定义的类。</p></li></ul> <h3 id="双亲委派模型">双亲委派模型</h3> <p>双亲委派模型是指除了启动类加载器，每个类加载器都应该有自己的父类加载器，当虚拟机加载一个类时，会先抛给最上层的启动类加载器进行类加载，当启动类加载器无法进行加载时，就会派给下层加载器进行加载，直至该类被加载成功。</p> <p>使用双亲委派模型的主要原因也是能够有效加载Java中的核心类库，例如我们自定义一个Java.lang.String类，该类并不会被加载成功，因为一开始由启动类加载器进行加载，在Java类库中发现已有Java.lang.String类，会直接加载进来，而不会加载自定义的类。</p> <h3 id="破坏双亲委派的三种情况">破坏双亲委派的三种情况</h3> <ul><li><p>历史原因</p> <p>双亲委派模型并不是一开始提出的，因此为了兼容之前的Java版本，用户可以去继承ClassLoader类并重写其中的loadClass方法来定义自己的类加载器。</p></li> <li><p>反向加载</p> <p>反向加载出现的原因主要是在有时候用户需要使用自定义的Java核心类库，因此必须打破双亲委派模型，虚拟机中引入了一个线程上下文类加载器，通过重写Thread类的setContextLoader()来自定义加载哪个类，举个例子，例如常用的mysql jdbc驱动包，我们需要加载外部的mysql-connector类库，但是这个jdbc类库在Java中是已经被定义了的，因此需要通过线程上下文类加载器来使原本启动类加载器进行加载改为系统类加载器进行加载。</p></li> <li><p>结构复杂化</p> <p>这种情况下类加载不再是树形结构，而是变成了复杂的网状结构，主要是针对于代码的动态性进行调整，例如代码热部署等，代码改变后无需进行重启，也就代表不需要重复加载，只需要加载部分内容就可以运行。</p></li></ul> <h2 id="gc调优">GC调优</h2> <h3 id="jvm-指令">JVM 指令</h3> <table><thead><tr><th style="text-align:center;">指令</th> <th style="text-align:center;">作用</th></tr></thead> <tbody><tr><td style="text-align:center;">jps</td> <td style="text-align:center;">查看所有的虚拟机进程端口</td></tr> <tr><td style="text-align:center;">jInfo</td> <td style="text-align:center;">查看虚拟机配置参数信息</td></tr> <tr><td style="text-align:center;">jstat</td> <td style="text-align:center;">查看虚拟机的运行数据、内存使用情况等</td></tr> <tr><td style="text-align:center;">jmap</td> <td style="text-align:center;">生成虚拟机的内存转储快照</td></tr> <tr><td style="text-align:center;">jhat</td> <td style="text-align:center;">查看heapdump信息</td></tr> <tr><td style="text-align:center;">jstack</td> <td style="text-align:center;">查看虚拟机的线程快照</td></tr> <tr><td style="text-align:center;">jconsole</td> <td style="text-align:center;">可视化虚拟机运行的各内存区域、新生代、老年代等信息</td></tr> <tr><td style="text-align:center;">jvisualvm</td> <td style="text-align:center;">可视化来监控Java应用程序的性能并跟踪</td></tr></tbody></table> <h3 id="怎样实现gc调优">怎样实现GC调优</h3> <ol><li>GC调优的原则：
<ul><li>尽量少的full gc</li> <li>优化虚拟机的参数</li></ul></li> <li>具体措施
<ul><li>尽量让对象存储在新生代中，这样是保证更多的发生minor gc，而使老年代中的内存占用更少，从而导致更少的full gc。</li> <li>大对象进入老年代，因为新生代中存储大对象的话，就会导致新生代中的可分配内存变得更少，在对象年龄判定中，相同年龄的对象内存大于Survivor区中内存的一半时，就会将当前年龄的对象全部进入老年代，这也会导致更多的full gc。</li> <li>设置合适进入老年代的年龄，减少老年代的内存占用，降低full gc发生的频率。</li> <li>设置合适的堆内存、栈内存等参数，堆大小有两个参数：-Xms初始化堆大小、-Xmm最大堆内存。</li></ul></li></ol></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2021/4/9 下午9:08:41</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c8d125c6 data-v-c8d125c6><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c8d125c6><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c8d125c6></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c8d125c6></path></svg></div><APlayer audio="" fixed="true" mini="true" theme="#b7daff" loop="loop" order="random" preload="auto" volume="0.08" mutex="true" lrc-type="0" list-folded="true" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer></div></div>
    <script src="/assets/js/app.0e76bb72.js" defer></script><script src="/assets/js/3.c5829877.js" defer></script><script src="/assets/js/1.695f3f80.js" defer></script><script src="/assets/js/229.0f8a6911.js" defer></script>
  </body>
</html>
